package com.qf.smsplatform.strategy.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.strategy.executor.StrategyExecutor;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听 pre_send_sms_topic队列中的消息（也就是接口模块发送的消息）
 * @author zjw
 */
@Component
public class PreSendListener {

    @Autowired
    private StrategyExecutor executor;

    @RabbitListener(queues = {RabbitMQConstants.TOPIC_PRE_SEND})
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
        // do something
        executor.execute(submit);

        // 手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
